package com.bckj.fastboot.core.extra.stage;

import com.bckj.fastboot.core.util.ExecutionContext;
import lombok.Getter;
import lombok.Setter;

import java.util.Map;
import java.util.Set;

/**
 * 阶段上下文基类（所有阶段共享数据的载体）
 */
@Setter
@Getter
public class BaseStageContext implements ExecutionContext {
    // 基础元数据
    private String stageId;          // 当前执行阶段ID
    private Map<String, Object> attrs; // 通用属性存储（键值对）
    private Exception exception;     // 阶段执行异常（可选）

    public BaseStageContext(Map<String, Object> attrs) {
        this.attrs = attrs;
    }

    public <V> V get(String key, Class<V> clazz) {
        Object value = get(key);
        return value != null ? clazz.cast(value) : null;
    }

    @Override
    public void put(String key, Object value) {
        attrs.put(key, value);
    }

    @Override
    public Object get(String key) {
        return attrs.get(key);
    }

    @Override
    public boolean containsKey(String key) {
        return attrs.containsKey(key);
    }

    @Override
    public Set<String> keySet() {
        return attrs.keySet();
    }
}